﻿Module LoadScript
    Public Sub LoadScript(ByVal SCRIPTnum As String)
        MainProgram.ScriptData = MainProgram.GetFileContents(MainProgram.DirScripts, MainProgram.sErr)
        If MainProgram.sErr = "" Then
            Dim tempvar As Integer = InStr(MainProgram.ScriptData, "SCRIP#" + SCRIPTnum + "(")
            Dim tempvar2 As Integer
            MainProgram.ScriptData_INTRO = ""
            MainProgram.ScriptData_REFRESH = ""
            MainProgram.ScriptData_OPTIONS = ""
            MainProgram.ScriptData_Option(0) = ""
            MainProgram.ScriptData_Option(1) = ""
            MainProgram.ScriptData_Option(2) = ""
            MainProgram.ScriptData_Option(3) = ""
            MainProgram.ScriptData_Option(4) = ""
            Dim test As String
            If tempvar > 0 Then
                For tempvar2 = InStr(MainProgram.ScriptData, "SCRIP#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                    If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                        MainProgram.ScriptData_INTRO = Replace(Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))))), " ", "")
                        Exit For
                    End If
                Next
                tempvar = InStr(MainProgram.ScriptData, "INTRO#" + SCRIPTnum + "(")
                For tempvar2 = InStr(MainProgram.ScriptData, "INTRO#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                    If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                        MainProgram.ScriptData_INTRO = Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), +tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum)))))
                        Exit For
                    End If
                Next
                tempvar = InStr(MainProgram.ScriptData, "OPTIO#" + SCRIPTnum + "(")
                If tempvar > 0 Then
                    For tempvar2 = InStr(MainProgram.ScriptData, "OPTIO#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                        If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                            MainProgram.ScriptData_OPTIONS = Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum)))))
                            test = MainProgram.ScriptData_OPTIONS
                            Exit For
                        End If
                    Next
                End If
                tempvar = InStr(MainProgram.ScriptData, "SUBO1#" + SCRIPTnum + "(")
                If tempvar > 0 Then
                    For tempvar2 = InStr(MainProgram.ScriptData, "SUBO1#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                        If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                            MainProgram.ScriptData_Option(0) = Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum)))))
                            test = MainProgram.ScriptData_Option(0)
                            Exit For
                        End If
                    Next
                End If
                tempvar = InStr(MainProgram.ScriptData, "SUBO2#" + SCRIPTnum + "(")
                If tempvar > 0 Then
                    For tempvar2 = InStr(MainProgram.ScriptData, "SUBO2#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                        If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                            MainProgram.ScriptData_Option(1) = Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum)))))
                            Exit For
                        End If
                    Next
                End If
                tempvar = InStr(MainProgram.ScriptData, "SUBO3#" + SCRIPTnum + "(")
                If tempvar > 0 Then
                    For tempvar2 = InStr(MainProgram.ScriptData, "SUBO3#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                        If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                            MainProgram.ScriptData_Option(2) = Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum)))))
                            Exit For
                        End If
                    Next
                End If
                tempvar = InStr(MainProgram.ScriptData, "SUBO4#" + SCRIPTnum + "(")
                If tempvar > 0 Then
                    For tempvar2 = InStr(MainProgram.ScriptData, "SUBO4#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                        If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                            MainProgram.ScriptData_Option(3) = Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum)))))
                            Exit For
                        End If
                    Next
                End If
                tempvar = InStr(MainProgram.ScriptData, "SUBO5#" + SCRIPTnum + "(")
                If tempvar > 0 Then
                    For tempvar2 = InStr(MainProgram.ScriptData, "SUBO5#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                        If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                            MainProgram.ScriptData_Option(4) = Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum)))))
                            Exit For
                        End If
                    Next
                End If
                tempvar = InStr(MainProgram.ScriptData, "REFRE#" + SCRIPTnum + "(")
                If tempvar > 0 Then
                    For tempvar2 = InStr(MainProgram.ScriptData, "REFRE#" + SCRIPTnum + "(") To Len(MainProgram.ScriptData) Step 1
                        If Mid(MainProgram.ScriptData, tempvar2, 1) = ")" Then
                            MainProgram.ScriptData_REFRESH = Mid(MainProgram.ScriptData, tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum))), tempvar2 - (tempvar + 7 + Len(LTrim(RTrim(SCRIPTnum)))))
                            Exit For
                        End If
                    Next
                End If
            End If
        Else
            Debug.WriteLine("Error retrieving file: " & MainProgram.sErr)
        End If
    End Sub
End Module
